#include "usbd_common.h"
#include "usbd_cdc_if.h"
#include "usbd_storage_if.h"

const USBD_COM_ITFTypeDef USBD_COMP_Interface = {
    .cdcItf = &USBD_CDC_fops,
    .storageItf = &USBD_Storage_Interface_fops_FS
};

USBD_COM_DataTypeDef USBCOMHandler;

/// @brief USB注册通用接口
/// @param pdev 
/// @param fops 
/// @return 
uint8_t USBD_COM_RegisterCommonInterface(USBD_HandleTypeDef *pdev)
{
    pdev->pUserData = (void*)&USBD_COMP_Interface;
    return USBD_OK;
}

/// @brief USB类通用的预初始化
/// @return 
uint8_t USBD_COM_PreInit(USBD_HandleTypeDef *pdev)
{
    if (pdev->pClassData == NULL)
    {
        // pdev->pClassData = USBD_malloc(sizeof(USBD_COM_DataTypeDef));
        pdev->pClassData = &USBCOMHandler;
        return USBD_OK;
    }
    else
    {
        return USBD_FAIL;
    }
}

/// @brief USB类通用的预反初始化
/// @return 
uint8_t USBD_COM_NextDeInit(USBD_HandleTypeDef *pdev)
{
    if (pdev->pClassData != NULL)
    {
        //USBD_free(pdev->pClassData);
        pdev->pClassData = NULL;
        return USBD_OK;
    }
    else
    {
        return USBD_FAIL;
    }
}